/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package menusearch.ui;

import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import menusearch.db.SearchParameters;

/**
 *
 * @author Joshua McKenzie
 */
public class SearchMenusPanel extends javax.swing.JPanel {

    /**
     * Creates new form SearchMenusPanel
     */
    public SearchMenusPanel() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        menuSponsorTextField = new javax.swing.JTextField();
        sponsorLabel = new javax.swing.JLabel();
        yearLabel = new javax.swing.JLabel();
        menuYearTextField = new javax.swing.JTextField();
        locationLabel = new javax.swing.JLabel();
        menuLocationTextField = new javax.swing.JTextField();
        venueLabel = new javax.swing.JLabel();
        menuVenueTextField = new javax.swing.JTextField();
        currencyLabel = new javax.swing.JLabel();
        menuCurrencyTextField = new javax.swing.JTextField();
        dishLabel = new javax.swing.JLabel();
        menuDishTextField = new javax.swing.JTextField();
        eventLabel = new javax.swing.JLabel();
        menuEventTextField = new javax.swing.JTextField();
        occasionLabel = new javax.swing.JLabel();
        menuOccasionTextField = new javax.swing.JTextField();
        menuPanelClearButton = new javax.swing.JButton();
        menuPanelSearchButton = new javax.swing.JButton();
        menuPanelExitButton = new javax.swing.JButton();
        titleLabel = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();

        sponsorLabel.setText("Sponsor:");

        yearLabel.setText("Year:");

        locationLabel.setText("Location:");

        venueLabel.setText("Venue:");

        currencyLabel.setText("Currency Type:");

        dishLabel.setText("Dish Keyword:");

        eventLabel.setText("Event:");

        occasionLabel.setText("Occasion:");

        menuPanelClearButton.setText("Clear");
        menuPanelClearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPanelClearButtonActionPerformed(evt);
            }
        });

        menuPanelSearchButton.setText("Search");
        menuPanelSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPanelSearchButtonActionPerformed(evt);
            }
        });

        menuPanelExitButton.setText("Exit");
        menuPanelExitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPanelExitButtonActionPerformed(evt);
            }
        });

        titleLabel.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        titleLabel.setText("Search for Menus:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(titleLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(venueLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(menuVenueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(42, 42, 42)
                                .addComponent(occasionLabel))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(locationLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(menuLocationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(42, 42, 42)
                                .addComponent(eventLabel))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(sponsorLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(menuSponsorTextField)
                                    .addGap(42, 42, 42)
                                    .addComponent(currencyLabel))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(yearLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(menuYearTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(dishLabel))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(menuOccasionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(menuDishTextField)
                            .addComponent(menuCurrencyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(menuEventTextField)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(menuPanelClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(menuPanelSearchButton)
                        .addGap(18, 18, 18)
                        .addComponent(menuPanelExitButton)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {currencyLabel, dishLabel, eventLabel, locationLabel, occasionLabel, sponsorLabel, venueLabel, yearLabel});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {menuCurrencyTextField, menuDishTextField, menuEventTextField, menuLocationTextField, menuOccasionTextField, menuSponsorTextField, menuVenueTextField, menuYearTextField});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {menuPanelClearButton, menuPanelExitButton, menuPanelSearchButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(titleLabel)
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(sponsorLabel)
                            .addComponent(menuSponsorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(currencyLabel)
                            .addComponent(menuCurrencyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(yearLabel)
                            .addComponent(menuYearTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(dishLabel)
                            .addComponent(menuDishTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(menuLocationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(locationLabel)
                            .addComponent(eventLabel)
                            .addComponent(menuEventTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(venueLabel)
                            .addComponent(menuVenueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(occasionLabel)
                            .addComponent(menuOccasionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(52, 52, 52)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(menuPanelClearButton)
                            .addComponent(menuPanelSearchButton)
                            .addComponent(menuPanelExitButton))
                        .addGap(0, 96, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void menuPanelClearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuPanelClearButtonActionPerformed
        menuSponsorTextField.setText(" ");
        menuYearTextField.setText(" ");
        menuLocationTextField.setText(" ");
        menuVenueTextField.setText(" ");
        menuCurrencyTextField.setText(" ");
        menuDishTextField.setText(" ");
        menuEventTextField.setText(" ");
        menuOccasionTextField.setText(" ");
    }//GEN-LAST:event_menuPanelClearButtonActionPerformed

    /**
     * Creating public method to access Search Parameters
     * @return SearchParameters
     */
    public SearchParameters buildSearchParameters()
    {
        
       
        
          SearchParameters param = new SearchParameters();

        //brings in SearchParameters class to pass methods to

        int[] year = new int [2];
        String aYear = "";
        int yearAsNumber;
        //Variables to pass year

        String sponsor, event, venue, occasion, location, currency, dish;

        if(menuYearTextField.getText().isEmpty())
        {
            yearAsNumber = 0;
            year[0] = yearAsNumber;
        }
        else 
                { aYear = menuYearTextField.getText();
               yearAsNumber = Integer.parseInt(aYear);
               year[0] = yearAsNumber;
               year[1] = yearAsNumber;
               
               for (int i : year)
               {
                   System.out.println("The year is " + i);
               }
                }

        if(menuSponsorTextField.getText().isEmpty())
        {
            sponsor = null;
           
        }
        else sponsor = menuSponsorTextField.getText();
        
        if (menuEventTextField.getText().isEmpty())
        {
           event = null;
        }
        else event = menuEventTextField.getText();
        
        if (menuVenueTextField.getText().isEmpty())
        {
           venue = null;
        }
        else venue = menuVenueTextField.getText();
        
        if (menuLocationTextField.getText().isEmpty())
        {
            location = null;
        }
        else location = menuLocationTextField.getText();
        
        if (menuOccasionTextField.getText().isEmpty())
        {
            occasion = null;
        }
        else occasion = menuOccasionTextField.getText();
        
        if (menuCurrencyTextField.getText().isEmpty())
        {
            currency = null;
        }
        else currency = menuCurrencyTextField.getText();
        
        if (menuDishTextField.getText().isEmpty())
        {
            dish = null;
        }
        else dish = menuDishTextField.getText();
        
        
        
        param.setSponsor(sponsor);
        param.setEvent(event);
        param.setVenue(venue);
        param.setPlace(location);
        param.setOccasion(occasion);
        param.setCurrency(currency);
        param.setDish(dish);
        param.setYear(year);
        //passes values to SeacrhParameters class
        
        return param;
    }
    
    private void menuPanelSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuPanelSearchButtonActionPerformed
        
        /*
        try {
            SearchParameters p = buildSearchParameters();
            MenuResultsPage x = new MenuResultsPage();
            x.menuListResults(p);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(SearchMenusPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(SearchMenusPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
      */
        
        
        
    }//GEN-LAST:event_menuPanelSearchButtonActionPerformed
    public void searchBtnAddActionListener(ActionListener al) {
    menuPanelSearchButton.addActionListener(al);
  }

//Calls public buildSearchParameters method 
    private void menuPanelExitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuPanelExitButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_menuPanelExitButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel currencyLabel;
    private javax.swing.JLabel dishLabel;
    private javax.swing.JLabel eventLabel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel locationLabel;
    private javax.swing.JTextField menuCurrencyTextField;
    private javax.swing.JTextField menuDishTextField;
    private javax.swing.JTextField menuEventTextField;
    private javax.swing.JTextField menuLocationTextField;
    private javax.swing.JTextField menuOccasionTextField;
    private javax.swing.JButton menuPanelClearButton;
    private javax.swing.JButton menuPanelExitButton;
    private javax.swing.JButton menuPanelSearchButton;
    private javax.swing.JTextField menuSponsorTextField;
    private javax.swing.JTextField menuVenueTextField;
    private javax.swing.JTextField menuYearTextField;
    private javax.swing.JLabel occasionLabel;
    private javax.swing.JLabel sponsorLabel;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JLabel venueLabel;
    private javax.swing.JLabel yearLabel;
    // End of variables declaration//GEN-END:variables
}
